<?php
use think\migration\Migrator;
use think\migration\db\Column;

class CreatePointsLogs extends Migrator
{
    public function change()
    {
        $this->table('points_logs', ['engine' => 'InnoDB'])
            ->addColumn('user_id', 'integer', ['comment' => '用户ID'])
            ->addColumn('type', 'string', ['limit' => 20, 'comment' => '类型：recharge充值/consume消费'])
            ->addColumn('points', 'integer', ['comment' => '积分数量，正数表示充值，负数表示消费'])
            ->addColumn('balance', 'integer', ['comment' => '变动后的余额'])
            ->addColumn('description', 'string', ['limit' => 255, 'comment' => '描述'])
            ->addColumn('order_id', 'string', ['limit' => 64, 'null' => true, 'comment' => '充值订单ID'])
            ->addColumn('task_id', 'string', ['limit' => 64, 'null' => true, 'comment' => '消费任务ID'])
            ->addColumn('operator_id', 'integer', ['null' => true, 'comment' => '操作人ID，系统操作为null'])
            ->addColumn('create_time', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间'])
            ->addIndex(['user_id'])
            ->addIndex(['type'])
            ->addIndex(['create_time'])
            ->create();
    }
} 